﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ZLCMS.Business;
using ZLCMS.Business.DwzFrame;
using ZLCMS.Business.Util;
using ZLCMS.Data.Model;
using ZLCMS.Data.Common;
using NHibernate.Criterion;
using NHibernate;
using DotNet.Common.NHibernateUtil;
using ZLCMS.Web.SystemManage.Basics.ProductSKU;
using System.Collections.Generic;
using ZLCMS.Commands.User.Commands.Order;
using ZLCMS.Commands.Data;

namespace ZLCMS.Web.SystemManage.Basics.Shop.Order
{
    public partial class OrderDetail : System.Web.UI.Page
    {
        protected FrameHelper _framePage;

        protected OrderData OrderData { get; set; }


        protected void Page_Load(object sender, EventArgs e)
        {
            //初始化DWZ控件
            _framePage = new FrameHelper(this);

            //加载订单信息
            LoadOrderDetailResult result = new LoadOrderDetailCommand().Execute(new LoadOrderDetailParameter()
            {
                OrderNo = Request["no"],
                UserAccount = UserKit.GetUserAccount()
            }).Result;

            OrderData = result.Data;

            grid.DataSource = OrderData.ProductList;
            grid.DataBind();

            logs.DataSource = result.Logs;
            logs.DataBind();

            returns.DataSource = result.ReturnsLogs;
            returns.DataBind();

            refund.DataSource = result.RefundData;
            refund.DataBind();
        }

        protected void returns_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater rep = e.Item.FindControl("logs") as Repeater;
                IDictionary returnData = (IDictionary)e.Item.DataItem;

                rep.DataSource = returnData["Process"];
                rep.DataBind();
            }
        }

        protected string GetImageHtml(string jsonString)
        {
            string imgHtml = "";
            foreach (var item in FileKit.FileList(jsonString)){

                imgHtml += string.Format("<a class='prettyPhoto' title='{0}' href='{0}'>点击预览</a></br>",item.FilePath);
            }
            return imgHtml;
        }
    }
}
